let mock = require('mockjs');
let uuid = require('uuid');
let testData = [];

for (let i = 0; i < 100; i++) {
  let progress;
  if (i%5===0) {
    progress = 100;
  } else {
    progress = mock.Random.natural(50, 100);
  }
  testData.push(mock.mock({
    "title": ({ context }) => {
      let category = context.root.category;
      if (category == 1) {
        return '信用宝-' + mock.mock(/\d{5}/);
      } else if (category == 2) {
        return '惠农宝-' + mock.mock(/\d{5}/);
      } else {
        return '消费宝-' + mock.mock(/\d{5}/);
      }
    },
    // "lendId": mock.mock('@id'),
    "lendId": uuid.v1(),
    "yield": mock.Random.natural(8, 15),
    "lendTerm": mock.Random.natural(3, 36),
    "progress": progress,
    "restAmount": ({ context }) => {
      let {root} = context;
      return root.lendAmount*(100-root.progress)/100;
    },
    "category":mock.Random.natural(1,3), 
    "lendType": mock.Random.natural(1,2),
    "lendAmount": mock.mock(/\d0{8,10}/) * 1,
    "payMethod": "先息后本",
    "beginDate": mock.Random.now('date', 'yyyy-MM-dd'),
    "raiseDate": mock.Random.natural(15,30),
    "transfer": "0",
    "costFee": "15%利息管理费"
  }))
}

const fs = require('fs');
const path = require('path');
fs.writeFileSync(path.resolve(__dirname,'lend.json'),JSON.stringify(testData));


